Record
A value of class Record is an unordered collection of properties. Like the properties of application objects, each property has a label, and the properties of a record are distinguished from each other by their label. There can be only one property with a particular label in any record.LITERAL EXPRESSIONS
Records appear in scripts as series of properties contained within braces and separated by commas. Each property has a label. Following the label is a colon, and following the colon, the value of the property. For example, the record
{ name:"Mitchell", height:70.5, weight:165 }contains three properties: Name (a string), Height (a real number), and Weight (an integer). The values assigned to properties can belong to any class.AppleScript evaluates expressions in a record before using the record in other expressions. For example, the record
{ name:"Mitchell", height:72 - 1.5, weight:150 + 15 }is equivalent to
{ name:"Mitchell", height:70.5, weight:165 }PROPERTIES
In addition to the properties that are specific to each record, two properties are common to all records:
Class
- The class identifier for the object. For most records, the value of the Class property is
record
. However, the Class property of a record is not read-only. AppleScript and applications use special records for certain data. For example, the Scriptable Text Editor uses special records to specify the styles (such asbold
andunderline
) of text objects. The value of the Class property for these records is the class identifier Text Style Info, as illustrated in this example:{class:Text Style Info, On Styles:{Bold}, ¬ Off Styles:{ Italic, Outline, Shadow}}If you define a Class property explicitly in a record, the value you define replaces the implicit Class property
Length
- An integer containing the number of properties in the record. This property is read-only.
record
described above.OPERATORS
The operators that can have records as operands are&
,=
,≠
, Starts With, Ends With, Contains, and Is Contained By.For detailed explanations and examples of how AppleScript operators treat records, see "Operators That Handle Operands of Various Classes," which begins on page 168.
COMMANDS HANDLED
You can count the properties in a record with the Count command. For example, the value of the following statement is2
.
count of {name:"Sue", mileage:4000} --result: 2Another way to count the properties in a record is with a Length property reference. For example, the value of the following reference is3
.
length of {name:"Sue", mileage:8000, city:"Sunnyvale"} --result: 3REFERENCE FORMS
The only reference form you can use with records is the Property reference form. For example, the following reference specifies the Mileage property of
a record.
mileage of {name:"Sue", mileage:8000, city:"Sunnyvale"} --result: 8000You cannot refer to properties in records by numeric index. For example,
the following reference, which uses the Index reference form on a record,
is not valid.
item 2 of { name:"Sue", mileage:8000, city:"Sunnyvale" } --result: not a valid referenceCOERCIONS SUPPORTED
AppleScript supports coercion of records to lists; however, all property labels are lost in the coercion and the resulting list cannot be coerced back to a record.NOTES
To specify a particular property of a record, you give its name. For example, if you assign the record to a variable, as in
copy { name:"Mitchell", height:70.5, weight:165 } to writeryou can then get the value of the Name property with the expression
name of writerA property of a record can contain a value of any class. You can change the class of a property simply by assigning a value belonging to another class.After you define a record, you cannot add additional properties to it. You can, however, concatenate records. For more information, see "Concatenation" on page 177.